package com.codermn.并发访问控制.同步代码块;

/**
 * <p>
 * 一般推荐使用最小区间使用原则，尽量不要直接在方法上加synchronized，比如经典的双重判定单例模式
 * </p>
 * @author jxau_scf
 * @date 2021/8/13 - 10:51
 */
public class Single {
    private static volatile Single instance;
    private Single(){}
    public static Single getInstance(){
        if (instance == null){
            synchronized (Single.class){
                if (instance == null){
                    instance = new Single();
                }
            }
        }
        return instance;
    }
}
